class PaymentController {
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ paymentList: Payment.list( params ) ]
    }

    def show = {
        def payment = Payment.get( params.id )

        if(!payment) {
            flash.message = "Payment not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ payment : payment ] }
    }

    def delete = {
        def payment = Payment.get( params.id )
        if(payment) {
            payment.delete()
            flash.message = "Payment ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Payment not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def payment = Payment.get( params.id )

        if(!payment) {
            flash.message = "Payment not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ payment : payment ]
        }
    }

    def update = {
        def payment = Payment.get( params.id )
        if(payment) {
            payment.properties = params
            if(!payment.hasErrors() && payment.save()) {
                flash.message = "Payment ${params.id} updated"
                redirect(action:show,id:payment.id)
            }
            else {
                render(view:'edit',model:[payment:payment])
            }
        }
        else {
            flash.message = "Payment not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def payment = new Payment()
        payment.properties = params
        return ['payment':payment]
    }

    def save = {
        def payment = new Payment(params)
        if(!payment.hasErrors() && payment.save()) {
            flash.message = "Payment ${payment.id} created"
            redirect(action:show,id:payment.id)
        }
        else {
            render(view:'create',model:[payment:payment])
        }
    }
}
